package logic

import (
	"context"
	"week1/textrpc/service"

	"week1/textrpc/internal/svc"
	"week1/textrpc/textrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BarrageShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBarrageShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BarrageShowLogic {
	return &BarrageShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BarrageShowLogic) BarrageShow(in *textrpc.BarrageShowReq) (*textrpc.BarrageShowRes, error) {
	// todo: add your logic here and delete this line
	barrage, err := service.GetBarrage()
	var datas []*textrpc.BarrageData
	for _, v := range barrage {
		//t := v.CreatedAt.Format(time.DateTime)

		var data = &textrpc.BarrageData{
			Id:       int32(v.ID),
			TextId:   v.TextId,
			UserId:   v.Userid,
			Comment:  v.Comment,
			Pid:      v.Pid,
			CreateAt: "三天前",
		}
		datas = append(datas, data)
	}
	if err != nil {
		return &textrpc.BarrageShowRes{Data: nil}, err
	}
	return &textrpc.BarrageShowRes{Data: datas}, nil
}
